/**
 * 判断字符串是否为空
 * @param str
 * @returns
 */
export function strIsEmpty(str: unknown): str is null | undefined {
  return typeof str === 'undefined' || str == null || str === '' || str === 'null';
}

/**
 * 判断对象是否为空
 * 判读数组是否为空
 * @param args
 * @returns boolean
 */
export function isEmpty(args: unknown): args is null | undefined {
  if (args === null || args === undefined)
    return true;
  if (Array.isArray(args))
    return args.length === 0;
  if (typeof args === 'object')
    return Object.keys(args).length === 0;
  return false;
}

/**
 * 判断变量是否是字符串
 * @param args
 */
export function isString(args: unknown): args is string {
  return Object.prototype.toString.call(args) === '[object String]';
}

/**
 * 判断变量是否是方法
 * @param args
 */
// eslint-disable-next-line ts/no-unsafe-function-type
export function isFunction(args: unknown): args is Function {
  return typeof args === 'function';
}

/**
 * 判断变量是否是数字
 * @param args
 */
export function isNumber(args: unknown): args is number {
  return Object.prototype.toString.call(args) === '[object Number]';
}

/**
 * 判断变量是否是Object
 * @param args
 */
export function isObject(args: unknown): args is object {
  return Object.prototype.toString.call(args) === '[object Object]';
}

/**
 * 判断变量是否是undefined
 * @param args
 * @returns
 */
export function isUndefined(args: unknown): args is undefined {
  return args === undefined;
}
/**
 * 判断变量是否是 Boolean
 * @param args
 */
export function isBool(args: unknown): args is boolean {
  return Object.prototype.toString.call(args) === '[object Boolean]';
}
/**
 * 判断是否是window对象
 * @param obj
 */
export function isWindow(obj: any) {
  return obj !== null && obj !== undefined && obj === obj.window;
}
